<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 350px;
            margin: 0 auto;
        }

        div textarea {
            outline: #ccc;
            resize: vertical;
            vertical-align: middle;
        }

        li {
            padding: 5px;
            position: relative;

        }

        li a {
            position: absolute;
            right: 5px;
            bottom: -1px;
            color: #ccc;
        }
    </style>
</head>

<body>
    <div>
        <textarea name="" id="" cols="30" rows="3"></textarea>
        <button>发送</button>
        <ul>
        </ul>
    </div>
    <script>
        var tx = document.querySelector('textarea')
        var btn = document.querySelector('button')
        var ul = document.querySelector('ul')
        btn.addEventListener('click', function (e) {
            console.log('dfh');
            if (tx.value == '') {
                alert('不能发送空内容')
                return 0;
            } else {
                var li = document.createElement('li')
                li.innerHTML = tx.value + '<a href="javascript:;">删除</a>'
                ul.appendChild(li)
                tx.value = ''
            }
                var a=document.querySelectorAll(' ul a')
                for(let i=0;i<a.length;i++){
                    a[i].addEventListener('click',function(e){
                       console.log(this.parentNode); 
                       ul.removeChild(this.parentNode)
                    })
                }
                console.log(a);
        })
    

    </script>
</body>

</html>